package com.durian.base.rxhttp.download

/**
 * 说明：Progress
 * <p/>
 * 作者：Fanly
 * <p/>
 * 类型：Class
 * <p/>
 * 时间：2020/08/25 11:39
 * <p/>
 * 版本：version 1.0
 */
open class Progress{

    var progress = 0//当前进度 0-100
    var currentSize = 0L//当前已完成的字节大小
    var totalSize = 0L//总字节大小

    constructor()

    constructor(progress: Int, currentSize: Long, totalSize: Long) {
        this.progress = progress
        this.currentSize = currentSize
        this.totalSize = totalSize
    }

    fun isFinish(): Boolean {
        return progress == 100
    }

    /**
     * 当前进度 0-100
     */
    fun updateProgress() {
        progress = if (totalSize == 0L) {
            0
        } else {
            (currentSize * 100 / totalSize).toInt()
        }
    }

    fun addTotalSize(addSize: Long) {
        totalSize += addSize
    }

    fun addCurrentSize(addSize: Long) {
        currentSize += addSize
    }
}